/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.deib.se2.meteocal.business.boundary;

import it.polimi.deib.se2.meteocal.business.boundary.InvitationManager;
import it.polimi.deib.se2.meteocal.business.entity.Invitation;
import javax.ejb.EJB;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class InvitationManagarIT {
    @EJB
    InvitationManager im;
   
    @PersistenceContext
    EntityManager entity;
    
    @Deployment
    public static WebArchive createArchiveAndDeploy() {
        return ShrinkWrap.create(WebArchive.class)
                .addClass(InvitationManager.class)
                .addPackage(Invitation.class.getPackage())
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }
    @Test
    public void InvitaionManagerShouldBeInjected() {
        assertNotNull(im);
    }
//    @Test
//    public void NotificationManagerShouldBeInjected() {
//        assertNotNull(nm);
//    }
    
    @Test
    public void EntityManagerShouldBeInjected() {
        assertNotNull(entity);
    }
   
    @Test
    public void newInvitaionShouldHaveId() {
        Invitation newInvitation = new Invitation();
        newInvitation.setId(null);
        try {
            im.save(newInvitation);
        } catch (Exception e) {
            assertTrue(true);
        }
    }
    
    @Test
    public void noSameIdForTwoInvitations() {
        Invitation i1 = new Invitation();
        Invitation i2 = new Invitation();
        i1.setId(Long.MIN_VALUE);
        i2.setId(Long.MIN_VALUE);
        try {
            im.save(i1);
            im.save(i2);
        } catch(Exception e) {
            assertTrue(true);
        }
    }
    @Test
    public void newInvitationsShouldReferToNotification() {
        Invitation inv = new Invitation();
        
        try{
            inv.getNotification_id();
        }catch(NullPointerException e ){
            assertTrue(true);
        }
    }
    @Test
    public void FindInvitationCanNotFindValueIfItDoesNotExist(){
        Invitation i= new Invitation();
        i.setId(Long.MIN_VALUE);
        try{
            im.find(i.getId());
        }catch(NullPointerException e){
            assertTrue(true);
        }
    }
  /* dovrebbe stare in IT ma non va
   @Test
   public void ifExistNotificationExistInvitationToo(){
       Notification n= new Notification();
       n.setId(Long.parseLong("123"));
       Invitation i= new Invitation();
       i.setId(Long.parseLong("456"));
       n.setInvitation(i);
       im.save(i);
       nm.save(n);
       assertSame(Long.parseLong("456"),nm.find(Long.parseLong("123")).getId());
   }
    */
}